//
//  LWlistView.m
//  LWShopItem
//
//  Created by mac on 17/4/14.
//  Copyright © 2017年 LWShop.com. All rights reserved.
//

#import "LWlistView.h"
#import "UIButton+CZAddition.h"
#import "UIColor+CZAddition.h"
#import <Masonry.h>
#import "Masonry.h"

@implementation LWlistView

{
    
    /**
     *  保存3个按钮的集合
     */
    NSArray<UIButton *> *_btnsArr;
    
}


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    
    return self;
}

#pragma MARK - UI
- (void)setupUI
{
    
    self.backgroundColor = [UIColor whiteColor];
    
    
    NSArray<NSString *> *titlesArr = @[@"最新", @"销量", @"价格"];
    
    [titlesArr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        UIButton *btn = [UIButton cz_textButton:obj fontSize:17 normalColor:[UIColor blackColor] selectedColor:[UIColor redColor]];
        
        btn.tag = idx;
        
        [btn addTarget:self action:@selector(categoryBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        
        
        [self addSubview:btn];
        
        
        
        
    }];
    
    
    
    //布局
    [self.subviews mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
    
    [self.subviews mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(self);
        
    }];
    
        
}

- (void)categoryBtnClick:(UIButton *)sender
{
    
    switch (sender.tag) {
        case  0:
            NSLog(@"点击了最新");
            break;
        case  1:
            NSLog(@"点击了销量");
            break;
        case  2:
            NSLog(@"点击了价格");
            break;
        
            
        default:
            break;
    }
}

     
@end
